#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdbool.h>

bool isLeapYear(int year) {
    if (year % 400 == 0) {
        return true;
    }
    else if (year % 100 == 0) {
        return false;
    }
    else if (year % 4 == 0) {
        return true;
    }
    else {
        return false;
    }
}
bool isValidDate(int year, int month, int day) {
    if (year < 1 || year > 3000) {
        return false;
    }
    if (month < 1 || month > 12) {
        return false;
    }
    int daysInMonth = 0;
    switch (month) {
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        daysInMonth = 31;
        break;
    case 4:
    case 6:
    case 9:
    case 11:
        daysInMonth = 30;
        break;
    case 2:
        if (isLeapYear(year)) {
            daysInMonth = 29;
        }
        else {
            daysInMonth = 28;
        }
        break;
    default:
        return false;
    }
    if (day < 1 || day > daysInMonth) {
        return false;
    }
    return true;
}
int main() {
    int year, month, day;
    scanf("%d %d %d", &year, &month, &day);
    if (isValidDate(year, month, day)) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
    return 0;
}